package UI;




import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mortbay.util.ajax.Continuation;
import org.mortbay.util.ajax.ContinuationSupport;

import Commnads.GuiCommands;


/**
 * Servlet implementation class ProgressBar
 */
public class PrgrsBar extends HttpServlet 
{
	private static final long serialVersionUID = 1L;
    private GuiCommands command; 
    private static Continuation cc;
    public PrgrsBar() 
    {
        super();
    }
    
    public PrgrsBar(GuiCommands com) 
    {
    	command = com;
    }
    
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException 
    {
    	cc = ContinuationSupport.getContinuation(req, null);
    	
    	int pre = 0;
    	while(true)
    	{
    		cc.suspend(0);
	    	pre = command.getPercent();
	    	String proB = "<div class=\"meter-wrap\">"+ 
	    				"<div class=\"meter-value\" style=\"background-color: #800080; width:"+pre+"%;\">"+
	    				"<div class=\"meter-text\" align=\"right\">"+pre+"%</div>"+        	
	    				"</div></div>";
	    	String script = "<script> parent.progB('"+proB+"'); </script>";
	    	resp.getWriter().println(script);
	    	resp.getWriter().flush();
    	}
    }

    
    public static void wake()
    {
    	if(cc != null)
    		cc.resume();
    }
}
